<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
	<title>商品分类</title>
	<%@include file="/static/include/head.jsp" %>
</head>
<body>
	<form id="searchForm" modelAttribute="goodsType" action="${ctx}/product/goodsType/" method="post" class="breadcrumb form-inline">
        <%-- 分页 --%>
		<input id="currentPage" name="currentPage" type="hidden" value="${page.currentPage}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<%-- 过滤条件 --%>
		<label>类型名称 ：</label>
		<input type="text" id="name" name="sp_name_LIKE" value="${name_LIKE}" maxlength="100" class="form-control input-sm"/>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnAdd" class="btn btn-info" type="button" value="新增" onclick="formWindow()"/>
	</form>
	<tags:message content="${message}"/>
	<div class="table-responsive">
	<table id="contentTable" class="table table-striped table-bordered table-hover table-condensed">
		<thead>
		<tr>
			<%--主键不输出--%>
			<th class="center">
				<label>
					<input type="checkbox" />
				</label>
			</th>
			<th>类型名称</th>
			<th>属性</th>
			<th>参数</th>
			<th>关联品牌</th>
			<th>关联规格</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.pageList}" var="goodsType">
		<tr>
			<td class="center">
				<label>
					<input type="checkbox" value="${goodsType.id}"/>
				</label>
			</td>
			<td>${goodsType.name}</td>
			<td>
			<c:if test="${goodsType.haveProp eq 0}">
				否
			</c:if>
			<c:if test="${goodsType.haveProp eq 1}">
				<button type="button" class="btn btn-xs btn-info" onclick="openPropsWindow('${ctx}/product/goodsType/typeProps?id=${goodsType.id}')"
						data-toggle="tooltip" data-placement="right" title="类型属性编辑">
					<span class="glyphicon glyphicon-edit"></span>
				</button>
			</c:if>
			</td>
			<td>
			<c:if test="${goodsType.haveParm eq 0}">
				否
			</c:if>
			<c:if test="${goodsType.haveParm eq 1}">
				<button type="button" class="btn btn-xs btn-info" onclick="openParamsWindow('${ctx}/product/goodsType/typeParams?id=${goodsType.id}')"
						data-toggle="tooltip" data-placement="right" title="类型参数编辑">
					<span class="glyphicon glyphicon-edit"></span>
				</button>
			</c:if>
			</td>
			<td>
			<c:if test="${goodsType.joinBrand eq 0}">
				否
			</c:if>
			<c:if test="${goodsType.joinBrand eq 1}">
				<button type="button" class="btn btn-xs btn-info" onclick="openWindow('${ctx}/product/goodsType/typeBrand?id=${goodsType.id}')"
						data-toggle="tooltip" data-placement="right" title="品牌关联编辑">
					<span class="glyphicon glyphicon-edit"></span>
				</button>
			</c:if>
			</td>
			<td>
			<c:if test="${goodsType.joinSpec eq 0}">
				否
			</c:if>
			<c:if test="${goodsType.joinSpec eq 1}">
				<button type="button" class="btn btn-xs btn-info" onclick="openWindow('${ctx}/product/goodsType/typeSpec?id=${goodsType.id}')"
						data-toggle="tooltip" data-placement="right" title="规格关联编辑">
					<span class="glyphicon glyphicon-edit"></span>
				</button>
			</c:if>
			</td>
			<td>
				<button type="button" class="btn btn-xs btn-info" onclick="formWindow('${goodsType.id}','view')"
						data-toggle="tooltip" data-placement="right" title="查看">
					<span class="glyphicon glyphicon-search"></span>
				</button>
				<button type="button" class="btn btn-xs btn-warning" onclick="formWindow('${goodsType.id}','edit')"
						data-toggle="tooltip" data-placement="left" title="修改">
					<span class="glyphicon glyphicon-pencil"></span>
				</button>
				<button type="button" class="btn btn-xs btn-danger" onclick="del('${goodsType.id}')"
						data-toggle="tooltip" data-placement="right" title="删除">
					<span class="glyphicon glyphicon-trash"></span>
				</button>
			</td>
		</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>

    <%-- pager bar（自定义标签）
    <j:page page="${page }" />
     --%>
	<%-- 如果不想用标签可以直接使用--%>
	${page }

	<%-- modal dialog --%>
    <%@include file="/static/include/modal.jsp"%>
    <%-- modal large dialog --%>
    <%@include file="/static/include/modal-lg.jsp"%>
</body>
<script type="text/javascript">
	$(function() {
		//on load do something
    });
	
	function formWindow(id,type) {
	    var url = '${ctx}/product/goodsType/form' ;
	    if(id){
	        url += "?id="+id;
		}
        if(type){
            if(url.indexOf("?") != -1){
                url += "&type="+type;
            }else{
                url += "?type="+type;
            }
        }
		$("#formModal").modal({
			show:true,
			keyboard: true,
			remote: url
		});
    }
	
	function openWindow(url) {
        $("#formModal").modal({
            show: true,
            keyboard: true,
            remote: url
        });
    }
	
	function openPropsWindow(url) {
		$("#formModal-lg").modal({
            show: true,
            keyboard: true
        }).load(url, function (e) {
            // this is executed when the content has loaded.
        	Prop.init();
        });
	}
	
	function openParamsWindow(url) {
        $("#formModal").modal({
            show: true,
            keyboard: true
        }).load(url, function (e) {
            // this is executed when the content has loaded.
        	Param.init();
        });
    }
	
    /**
	 * 分页回调函数
     * @param n
     * @param s
     * @returns {boolean}
     */
    function page(n,s){
        $("#currentPage").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }

    /**
     * 删除操作
     * @param id
     */
   function del(id) {
       confirm("确认要删除吗？", function(result){
       	if(result){
       		ajaxReq("${ctx}/product/goodsType/delete?id=" + id, function(){
       			$("#btnSubmit").click(); //刷新列表
       		});
       	}
       });
   }
</script>
</html>
